package com.yunzhi.net.utils;

import android.content.Context;
import android.os.Bundle;

import com.cloudknow.common.Constant;
import com.cloudknow.utils.PrefsUtil;

import java.io.File;

/**
 * Created by zjp on 2018/3/22 17:34.
 */

public class AppConfig {


    //    private Context mContext;
    private static AppConfig appConfig;
    private final static String APP_CONFIG = "config";


    public static AppConfig getAppConfig() {
        if (appConfig == null) {
            appConfig = new AppConfig();
        }
        return appConfig;
    }

    public String get(Context context, String key) {
        return SPUtils.getInstance().getString(key, "");
    }

    public void set(Context context, String key, String value) {
        SPUtils.getInstance().put(key, value);
    }


    public void remove(Context context, String... key) {
        for (String k : key) {
            SPUtils.getInstance().remove(k);
        }
    }


    public static void clearFile(Context context) {
        File file = new File(context.getFilesDir(), APP_CONFIG);
        if (file.exists()) {
            file.delete();
        }
    }

    /**
     * 获取用户Token
     *
     * @return
     */
    public String getToken(Context context) {
        String token = getProperty(context, "access_token");
        String t = "";
        if (token != null) {
            t = token;
        }
        return t;
    }


    /**
     * 获取用户Token
     *
     * @return
     */
    public String getUserToken(Context context) {
        String token = PrefsUtil.getString(context, Constant.accessToken);
        String t = "";
        if (token != null) {
            t = token;
        }
        return t;
    }

    /**
     * 设置用户Token
     *
     * @return
     */
    public void setUserToken(Context context, String token) {
        PrefsUtil.setString(context, Constant.accessToken, token);
    }

    /**
     * 获取cookie时传AppConfig.CONF_COOKIE
     *
     * @param key
     * @return
     */
    public String getProperty(Context context, String key) {
        return get(context, key);
    }


    public interface OnOpenWeChatResult {
        void open();
    }

    private OnOpenWeChatResult onOpenWeChatResult;

    public OnOpenWeChatResult getOnOpenWeChatResult() {
        return onOpenWeChatResult;
    }

    public void setOnOpenWeChatResult(OnOpenWeChatResult onOpenWeChatResult) {
        this.onOpenWeChatResult = onOpenWeChatResult;
    }
}
